<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item label="分销商" prop="useruuid"  v-show="isShow">
					<el-select v-model="filters.useruuid" clearable filterable  placeholder="请选择分销商" >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="datetime" placeholder="开始时间"  format="yyyy-MM-dd HH:mm:ss"   v-model="filters.createtime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="datetime" placeholder="结束时间" clearable format="yyyy-MM-dd HH:mm:ss"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="zeroBalanceQuery">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="logs" highlight-current-row v-loading="listLoading" border max-height="620" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="user.username" label="分销商户名称"   >
			</el-table-column>
			<el-table-column prop="balance" label="余额"   >
			</el-table-column>
			<el-table-column prop="createTime" label="时间"   >
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>

	</section>
</template>

<script>
    import util from '../../common/js/util'
	import {findAllDownShopInfo, zeroBalance} from '../../api/api';
    import moment from 'moment';
    export default {
        data() {
            return {
                filters: {
					useruuid:'',
					createtime:  moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') + " 00:00:00",
					endtime:''

                },
                users: [],
                logs:[],
                isShow: JSON.parse(sessionStorage.getItem("user")).usertype === 1 ? true : JSON.parse(sessionStorage.getItem("user")).usertype === 2 ? true : false,
                total: 0,
                start:0,
                pageSize: 10,
				users:[],
                listLoading: false,
            }
        },
        methods: {
            //性别显示转换

            handleCurrentChange: function (val) {
                this.start = val - 1;
                this.zeroBalanceQuery();
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                this.zeroBalanceQuery();
            },
			zeroBalanceQuery() {
                let para = {
                    start: this.start,
                    pageSize: this.pageSize,
					userId: this.filters.useruuid == "0" ? "" : this.filters.useruuid,
					createtime: (this.filters.createtime == "" || this.filters.createtime == undefined) ? "" : moment(this.filters.createtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
					endtime: (this.filters.endtime == "" || this.filters.endtime == undefined) ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                };
                this.listLoading = true;
				zeroBalance(para).then((datas) => {
                    this.listLoading = false;

                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.logs = data.result;
                        this.total = data.totalCount;
                    }
                });
            },findAllDownShopInfo:function(){
				let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
				findAllDownShopInfo(para).then(datas => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						if(data){
							this.users = data;
						}
					}
				});
			},
        },
		async mounted() {
        	await this.findAllDownShopInfo();
			await this.zeroBalanceQuery();
        }
    }

</script>

<style scoped>

</style>
